// 定时刷新ajax及清除定时器
$(function(){
    runajax();
    if((starttime*1000) > nowtime){
      clearInterval(timer);
    }else if((endtime*1000) < nowtime){
      clearInterval(timer);
    }else{
      clearInterval(timer); 
      timer = setInterval(runajax,1000);
    }
})
// 确定按钮隐藏框 
$(function(){
  $(".cancelBtn").click(function(){
      $(this).parent().parent().css('display','none');
  })
})
// 订阅弹窗清空按钮
$(function(){
   $("#clear1").click(function(){
      $("#lossWord").val('');
      var saleNum = $("#saleNum").html();
      $("#numUp").html(saleNum);
   });
   $("#clear2").click(function(){
      $("#downWord").val('');
      var saleNum = $("#saleNum").html();
      $("#numDown").html(saleNum);
   });
})
// 头部鼠标移入效果
$(function(){
   $('.header_l ul li a').css({'border-bottom':'0px #fff','color':'#20222c'});
   $('.header_l ul li:eq(1) a').css({'border-bottom':'2px solid #04b1f9','color':'#04b1f9'});
   $(".header_l ul li").mouseenter(function () {
      $(this).find("a").css({'color':'#04b1f9'});
   }).mouseleave(function () {
      $(this).find("a").css({'color':'#20222c'});
      $('.header_l ul li:eq(1) a').css({'border-bottom':'2px solid #04b1f9','color':'#04b1f9'});
   });
})
// 样式
$(document).ready(function(){
   $('.stock_nav li').eq(0).addClass('nav_active');
   $('.stock_money').eq(0).show();
   $('.stock_nav li').click(function(){
      $('.stock_nav li').eq($(this).index()).addClass('nav_active').siblings().removeClass('nav_active');
      $('.stock_money').hide().eq($(this).index()).show();
   })
})
// 订阅右侧代码滚动
$(function(){
   var j_Master = $("#j_Slide_Box");
   var j_Master_length = j_Master.children().length;
   if (j_Master_length > 5) {
      setInterval(function () {
         var j_All = j_Master.children();
         var j_last = $(j_All[j_All.length - 1]);
         var j_first = $(j_All[0]);
         j_first.slideDown("slow");
         j_first.addClass('active');
         j_first.next().removeClass('active');
         setTimeout(function () {
            j_last.remove();
            j_last.css({ display: 'none' });
            j_last.prependTo(j_Master);
         }, 1000);
      }, 3000);
   }
})
// 止盈止损键盘事件 弹框
$(function(){
  // 止盈键盘事件
   $("#lossWord").keyup(function(){
      var profit=Number($.trim($(this).val()));
      //alert(profit);
      var reg=/^[0-9]{2,3}$/;
      if(!reg.test(profit)) {
         layer.tips('止盈请输入11-499的整数！','#lossWord');
      }else if( !isInteger(profit)){
         layer.tips('止盈请输入11-499的整数！','#lossWord');
      }else{
         // 判断黄金，日元，原油及其他
         var symble = $("#countryname").html();  //获取当前的品种
         var direction = $(".direction").html(); //获取用户是买入还是卖出
         var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
         // 获取节点
         if ((userAgent.indexOf("Chrome") > -1)){
            if( $.trim($('#saleNum').children().children().html()) == ''){
               var saleNum=$.trim($('#saleNum').html());
               var lossWord = $.trim($("#lossWordFont").html());
               var downWordFont = $.trim($("#downWordFont").html());
            }else{
               var saleNum=$.trim($('#saleNum').children().children().html());
               var lossWord =$.trim( $("#lossWordFont").children().children().html());
               var downWordFont =$.trim( $("#downWordFont").children().children().html());
            }
         }else{
            var saleNum=$.trim($('#saleNum').html());
            var lossWord = $.trim($("#lossWordFont").html());
            var downWordFont = $.trim($("#downWordFont").html());
         }
         //alert(saleNum);
         saleNum = $.trim(saleNum);
         // 买空
         if(direction == '空') {
            // 判断品种
            if(symble == 'XAUUSD') {
               // 美金
               saleNum= (parseFloat(saleNum) - parseFloat(profit/10)).toFixed(2);
               // console.log(saleNum);
            }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
               // 日元
               saleNum= (parseFloat(saleNum) - parseFloat(profit/100)).toFixed(3);
            }else if(symble == 'NYOL20'){
               // 原油
               saleNum= (parseFloat(saleNum) - parseFloat(profit/100)).toFixed(2);
            }else{
               saleNum= (parseFloat(saleNum) - parseFloat(profit/10000)).toFixed(5);
            }
            $("#numUp").html(parseFloat(saleNum));
         }else if(direction == '多'){   // 买多

            if(symble == 'XAUUSD') {   // 美金
               saleNum= (parseFloat(saleNum) + parseFloat(profit/10)).toFixed(2);
            }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
               // 日元
               saleNum= (parseFloat(saleNum) + parseFloat(profit/100)).toFixed(3);
            }else if(symble == 'NYOL20'){   // 原油
               saleNum= (parseFloat(saleNum) + parseFloat(profit/100)).toFixed(2);
            }else{
               saleNum= (parseFloat(saleNum) + parseFloat(profit/10000)).toFixed(5);
            }
            $("#numUp").html(parseFloat(saleNum));
         }
      }
   })
  // 止损框键盘事件
   $("#downWord").keyup(function(){

      var loss=Number($.trim($(this).val()));
      // console.log(profit);

      var reg=/^[0-9]+$/;

      if(!reg.test(loss)) {
         //alert("请输入数字");
         layer.tips('止损请输入11-99的整数！','#downWord');
      }else if( !isInteger(loss)){
         layer.tips('止损请输入11-99的整数！','#downWord');
      }else{

         // 判断黄金，日元，原油及其他
         var symble = $("#countryname").html();  //获取当前的品种
         var direction = $(".direction").html(); //获取用户是买入还是卖出
         var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
         // 获取节点
         if (userAgent.indexOf("Chrome") > -1){
            if( $.trim($('#saleNum').children().children().html()) == ''){
               var saleNum=$.trim($('#saleNum').html());
               var lossWord =$.trim( $("#lossWordFont").html());
               var downWordFont = $("#downWordFont").html();
            }else{
               var saleNum=$.trim($('#saleNum').children().children().html());
               var lossWord = $("#lossWordFont").children().children().html();
               var downWordFont = $("#downWordFont").children().children().html();
            }
         }else{
            var saleNum=$.trim($('#saleNum').html());
            var lossWord =$.trim( $("#lossWordFont").html());
            var downWordFont = $("#downWordFont").html();
         }
      }

      if(direction == '空') {
         // 买空
         // 判断品种
         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) + parseFloat(loss/10)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) + parseFloat(loss/100)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) + parseFloat(loss/100)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) + parseFloat(loss/10000)).toFixed(5);
         }
         $("#numDown").html(parseFloat(saleNum));
      }else if(direction == '多'){
         // 买多
         // 判断品种
         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) - parseFloat(loss/10)).toFixed(2);

         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) - parseFloat(loss/100)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) - parseFloat(loss/100)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) - parseFloat(loss/10000)).toFixed(5);
         }
         $("#numDown").html(parseFloat(saleNum));
      }
      // console.log(saleNum);

   })
})
// 止盈止损函数取模调用
function isInteger(obj) {
   return obj%1 === 0
}
// 计算器
function saleAdd(obj,obj1){   //obj代表 1:止盈，2:止损  obj1代表 1:+ ，2:-
   var profit = Number($.trim($("#lossWord").val()));   //获取用户填写的止盈止损点
   var loss = Number($("#downWord").val());
   if(obj == 1){
      if(obj1 == 2){
         profit++;
      } else if(obj1 == 1){
         if(profit > 1){
            profit--;
         }else{
            return ;
         }
      }
      $("#lossWord"). val(profit);

   }else if(obj == 2){
      if(obj1 == 2){
         loss++;
      }else if(obj1 == 1){
         if(loss > 1){
            loss--;
         }else{
            return ;
         }
      }
      $("#downWord"). val(loss);
   }

   var symble = $("#countryname").html();  //获取当前的品种
   var direction = $(".direction").html(); //获取用户是买入还是卖出


   // 判断品种
   if(symble == 'XAUUSD') {   // 美金
      profit = (profit/10);
      loss = (loss/10);
   }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
      // 日元
      profit = (profit/100);
      loss = (loss/100);
   }else if(symble == 'NYOL20'){  // 原油
      loss = (loss/100);
   }else{  //其他
      profit = (profit/10000);
      loss = (loss/10000);
   }


   var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
   // 获取节点
   if (!(userAgent.indexOf("Chrome") > -1)){
      var saleNum=$.trim($('#saleNum').children().children().html());
   }else{
      var saleNum=$.trim($('#saleNum').html());
   }


   if($.trim(direction) == '空'){
      if(obj == 1 && obj1 == 1){    //买空-->止盈的减按钮
         var saleNum =$.trim($("#numUp").html());
         if(symble == 'XAUUSD') { // 美金
            saleNum= (parseFloat(saleNum) + parseFloat(0.1)).toFixed(2);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){  // 原油
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) + parseFloat(0.0001)).toFixed(5);
         }
         $("#numUp").html(parseFloat(saleNum));
      }else if(obj == 1 && obj1 == 2){//买空-->止盈的加按钮
         var saleNum =$.trim($("#numUp").html());
         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) - parseFloat(0.1)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) - parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) - parseFloat(0.01)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) - parseFloat(0.0001)).toFixed(5);
         }
         $("#numUp").html(parseFloat(saleNum));
      }
   }else{  //买多，即买入
      if(obj == 1 && obj1 == 1){//买多-->止盈的减按钮
         var saleNum = $.trim($("#numUp").html());
         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) - parseFloat(0.1)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            // alert(parseFloat(profit));
            saleNum= (parseFloat(saleNum) - parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) - parseFloat(0.01)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) - parseFloat(0.0001)).toFixed(5);
         }
         $("#numUp").html(parseFloat(saleNum));
      }else if(obj == 1 && obj1 == 2){//买多-->止盈的加按钮
         var saleNum = $.trim($("#numUp").html());
         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) + parseFloat(0.1)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) + parseFloat(0.0001)).toFixed(5);
         }
         $("#numUp").html(parseFloat(saleNum));
      }

   }



   if(obj == 2 && obj1 == 1){ //止损减按钮
      var saleNum = $.trim($("#numDown").html());
      // alert(saleNum);
      if($.trim(direction) == '多'){//买多==>止损减按钮
         // var saleNum =  $.trim($("#numUp").html());
         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) + parseFloat(0.1)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) + parseFloat(0.0001)).toFixed(5);
         }
         $("#numDown").html(parseFloat(saleNum));
      }else{   //买空==>止损减按钮
         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) - parseFloat(0.1)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) - parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) - parseFloat(0.01)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) - parseFloat(0.0001)).toFixed(5);
         }
         $("#numDown").html(parseFloat(saleNum));

      }


   }else if(obj == 2 && obj1 == 2){   //止损加按钮
      var saleNum = $.trim($("#numDown").html());
      //alert(saleNum);
      if($.trim(direction) == '多'){//买多==>止损加按钮
         if(symble == 'XAUUSD') {
            // 美金
            saleNum = (parseFloat(saleNum) - parseFloat(0.1)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum = (parseFloat(saleNum) - parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum = (parseFloat(saleNum) - parseFloat(0.01)).toFixed(2);
         }else{
            saleNum = (parseFloat(saleNum) - parseFloat(0.0001)).toFixed(5);
         }
         $("#numDown").html(parseFloat(saleNum));

      }else{ //买空==>止损加按钮

         if(symble == 'XAUUSD') {
            // 美金
            saleNum= (parseFloat(saleNum) + parseFloat(0.1)).toFixed(2);
            // console.log(saleNum);
         }else if(symble == 'USDJPY' || symble == 'EURJPY' || symble == 'GBPJPY' || symble == 'CADJPY' || symble == 'CHFJPY' || symble == 'AUDJPY'){
            // 日元
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(3);
         }else if(symble == 'NYOL20'){
            // 原油
            saleNum= (parseFloat(saleNum) + parseFloat(0.01)).toFixed(2);
         }else{
            saleNum= (parseFloat(saleNum) + parseFloat(0.0001)).toFixed(5);
         }
         $("#numDown").html(parseFloat(saleNum));

      }

   }
}
// 获取鼠标指针相对于屏幕的水平坐标。
function specil(event){
   var e = event || window.event;
   return {'x':e.screenX,'y':screenY}
   // var stopDiv = document.getElementById('stopDiv').style.display = "block";
}
// 判断谷歌浏览器字符串
function downAdd(){
   // 判断谷歌浏览器
   var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
   // 获取节点
   if (userAgent.indexOf("Chrome") > -1){
      var saleNum=$('#saleNum').children().children().html();
   }else{
      var saleNum=$('#saleNum').html();
   }
}
//a标签划过显示协议内容   获取节点
function agreementDiv(){
   var status = $('#showAgreement').css('display');
   if(status == 'none'){
      $('#showAgreement').css('display','block');
   }else{
      $('#showAgreement').css('display','none');
   }
}
// 鼠标移除事件
function agreementHide(){
   var status = $('#showAgreement').css('display');
   if(status == 'block'){
      document.getElementById('showAgreement').style.display="none";
   }
}
// 弹框input清空，隐藏按钮
function hideDiv(){
   $("#lossWord").val('');
   $("#downWord").val('');
   document.getElementById('salePop').style.display="none";
   document.body.style.overflow='scroll';
}
//计算可设置最小点差
function point_diff(typename,current_point,open_point){
   var point_x = parseFloat(current_point) - parseFloat(open_point) ;
   var lastprice = 0;
   var profit_loss_point_x = $('input[name=oldpot_FX'+typename+']').val();
   if (typename == 'XAUUSD') {
      lastprice = Math.ceil(Math.abs(point_x)* 10) ;
   } else if (typename == 'NYOL20'){
      lastprice = Math.ceil(Math.abs(point_x)* 100);
   }else if( typename.indexOf('JPY')>0){
      lastprice = Math.ceil(Math.abs(point_x)* 100);
   }else{
      lastprice = Math.ceil(Math.abs(point_x)* 10000);
   }
   lastprice = lastprice<9?11:lastprice;
   lastprice = profit_loss_point_x > 0?11:lastprice;
   return lastprice;
}
// runajax 函数封装
function runajax(){
    var rounder = (new Date()).getTime();
    var url = "http://db2015.wstock.cn/wsDB_API2/stock.php?t="+ (new Date()).getTime()+"&symbol=FXXAUUSD,FXEURUSD,FXGBPUSD,FXUSDJPY,FXUSDCHF,FXUSDCAD ,FXAUDUSD,FXEURGBP,FXEURJPY,FXEURAUD,FXEURCHF,FXEURCAD,FXGBPCHF,FXGBPJPY ,FXCADJPY,FXAUDCAD,FXCHFJPY,FXAUDJPY&query=Date,Symbol,SP1,BP1,Name&u=liyunhe1228&p=liyunhe1228&r_type=2&num=20";
  $.ajax({
      type : "get",
      async : false, //同步请求
      url : url,
      data : '',
      timeout:1000,
      success:function(d){
        if(typeof d == "object"){
            var str='';
            var str1='';
            var str2='';
            for(var i =0 ;i < d.length;i++){
            if(typename && typename == d[i].Symbol.substr(2)){  //此处的typename是全局变量，不可以动
                var zhiying =  Number($.trim($("#lossWord").val()));  //获取用户输入的止盈点数
                var zhisun =  Number($.trim($("#downWord").val()));  //获取用户输入的止损点数
                if(type == 1){   //空
                    $('#saleNum').html(d[i].BP1);
                    $('#buyNum').html(d[i].SP1);
                    if(typename == 'XAUUSD'){
                        zhiying = (zhiying/10);
                        zhisun = (zhisun/10);
                        var lastprofile = (parseFloat(d[i].BP1) - parseFloat(zhiying)).toFixed(2);
                        var lastloss = (parseFloat(d[i].BP1) + parseFloat(zhisun)).toFixed(2);
                    }else if(typename == 'NYOL20'){
                        zhiying = (zhiying/100);
                        zhisun = (zhisun/100);
                        var lastprofile = (parseFloat(d[i].BP1) - parseFloat(zhiying)).toFixed(2);
                        var lastloss = (parseFloat(d[i].BP1) + parseFloat(zhisun)).toFixed(2);
                    }else if(typename.indexOf('JPY')>0){
                        zhiying = (zhiying/100);
                        zhisun = (zhisun/100);
                        if(typename.indexOf('USD')>0){  //判断是否是交叉盘
                            var lastprofile = (parseFloat(d[i].BP1) - parseFloat(zhiying)).toFixed(3);
                            var lastloss = (parseFloat(d[i].BP1) + parseFloat(zhisun)).toFixed(3);
                        }else{
                            var lastprofile = (parseFloat(d[i].SP1) - parseFloat(zhiying)).toFixed(3);
                            var lastloss = (parseFloat(d[i].SP1) + parseFloat(zhisun)).toFixed(3);
                        }
                        
                    }else{
                        zhiying = (zhiying/10000);
                        zhisun = (zhisun/10000);
                        if(typename.indexOf('USD')>0){  //判断是否是交叉盘
                            var lastprofile = (parseFloat(d[i].BP1) - parseFloat(zhiying)).toFixed(5);
                            var lastloss = (parseFloat(d[i].BP1) + parseFloat(zhisun)).toFixed(5);
                        }else{
                            var lastprofile = (parseFloat(d[i].SP1) - parseFloat(zhiying)).toFixed(5);
                            var lastloss = (parseFloat(d[i].SP1) + parseFloat(zhisun)).toFixed(5);
                        }
                        
                    }
                }else{  //多
                    $('#saleNum').html(d[i].SP1);
                    $('#buyNum').html(d[i].BP1);

                    if(typename == 'XAUUSD'){
                        zhiying = (zhiying/10);
                        zhisun = (zhisun/10);
                        var lastprofile = (parseFloat(d[i].SP1) + parseFloat(zhiying)).toFixed(2);
                        var lastloss = (parseFloat(d[i].SP1) - parseFloat(zhisun)).toFixed(2);
                    }else if(typename == 'NYOL20'){
                        zhiying = (zhiying/100);
                        zhisun = (zhisun/100);
                        var lastprofile = (parseFloat(d[i].SP1) + parseFloat(zhiying)).toFixed(2);
                        var lastloss = (parseFloat(d[i].SP1) - parseFloat(zhisun)).toFixed(2);
                    }else if(typename.indexOf('JPY')>0){
                        zhiying = (zhiying/100);
                        zhisun = (zhisun/100);
                        if(typename.indexOf('USD')>0){  //判断是否是交叉盘
                            var lastprofile = (parseFloat(d[i].SP1) + parseFloat(zhiying)).toFixed(3);
                            var lastloss = (parseFloat(d[i].SP1) - parseFloat(zhisun)).toFixed(3);
                        }else{
                            var lastprofile = (parseFloat(d[i].BP1) + parseFloat(zhiying)).toFixed(3);
                            var lastloss = (parseFloat(d[i].BP1) - parseFloat(zhisun)).toFixed(3);
                        }
                        
                    }else{
                        zhiying = (zhiying/10000);
                        zhisun = (zhisun/10000);
                        if(typename.indexOf('USD')>0){  //判断是否是交叉盘
                            var lastprofile = (parseFloat(d[i].SP1) + parseFloat(zhiying)).toFixed(5);
                            var lastloss = (parseFloat(d[i].SP1) - parseFloat(zhisun)).toFixed(5);
                        }else{
                            var lastprofile = (parseFloat(d[i].BP1) + parseFloat(zhiying)).toFixed(5);
                            var lastloss = (parseFloat(d[i].BP1) - parseFloat(zhisun)).toFixed(5);
                        }
                        
                    }
                }

                $('#numUp').html(parseFloat(lastprofile));
                $('#numDown').html(parseFloat(lastloss));
            }

            if(d[i].Symbol != 'FXXAUUSD' && d[i].Symbol != 'FXNYOL20'){
                  str+='<li class='+d[i].Symbol+'>';
                  str+='<div class="stock_top">';
                  str+='<div style="width:40px;height:30px;margin-top: 3px;"><img src="'+pingzhongImg+d[i].Symbol+'.png" alt="" /></div>';
                  str+='<span class="currency">';
                  str+=d[i].Symbol.substr(2);
                  str+='</span><span class="chinaname">'+d[i].Name+'</span></div>';
                  str+='<p class="stock_time">时间<span>';
                  str+=d[i].Date;
                  str+='</span></p>';

                  //如果页面不是第一次加载，也就是说数据已经存在的话，做对比，更改样式和图片    卖出
                  if($("input[name=sell"+d[i].Symbol+"]") && $("input[name=buy"+d[i].Symbol+"]")){
                      var selldata=$("input[name=sell"+d[i].Symbol+"]").val();
                      var buydata=$("input[name=buy"+d[i].Symbol+"]").val();
                  }
                  if(selldata){
                        if(selldata == d[i].BP1){
                            str+='<div class="stock_sell keep_active" id="getVal" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].BP1;

                        }else if(selldata < d[i].BP1){
                            str+='<div class="stock_sell up_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].BP1;
                            str+='<img src="'+J_up+'" class="up_down" alt="" />';

                        }else{
                            str+='<div class="stock_sell down_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].BP1;
                            str+='<img src="'+J_down+'" class="up_down" alt="" />';
                        }
                  }else{
                            str+='<div class="stock_sell up_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].BP1;
                            str+='<img src="'+J_up+'" class="up_down" alt="" />';
                  }

                  str+='</p><p>卖出价</p></div>';
                  //如果页面不是第一次加载，也就是说数据已经存在的话，做对比，更改样式和图片    买入
                  if(buydata){
                        if(buydata == d[i].SP1){
                            str+='<div class="stock_buy keep_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].SP1;

                        }else if(buydata < d[i].SP1){
                            str+='<div class="stock_buy up_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].SP1;
                            str+='<img src="'+J_up+'" class="up_down" alt="" />';

                        }else{
                            str+='<div class="stock_buy down_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].SP1;
                            str+='<img src="'+J_down+'" class="up_down" alt="" />';
                        }
                  }else{
                            str+='<div class="stock_buy down_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                            str+=d[i].SP1;
                            str+='<img src="'+J_up+'" class="up_down" alt="" />';
                    }



                  str+='</p><p>买入价</p></div>';
                  str+='<input type="hidden" name="sell'+d[i].Symbol+'" value='+d[i].BP1+'>';
                  str+='<input type="hidden" name="buy'+d[i].Symbol+'" value='+d[i].SP1+'></li>';

              }else if(d[i].Symbol == 'FXXAUUSD'){
                    str1+='<li class='+d[i].Symbol+'>';
                    str1+='<div class="stock_top">';
                    str1+='<div style="width:40px;height:30px;margin-top: 3px;"><img src="'+pingzhongImg+d[i].Symbol+'.png" alt="" /></div>';
                    str1+='<span class="currency">';
                    str1+=d[i].Symbol.substr(2);
                    str1+='</span><span class="chinaname">'+d[i].Name+'</span></div>';
                    str1+='<p class="stock_time">时间<span>';
                    str1+=d[i].Date;
                    str1+='</span></p>';

                    //如果页面不是第一次加载，也就是说数据已经存在的话，做对比，更改样式和图片    卖出
                    if($("input[name=sell"+d[i].Symbol+"]") && $("input[name=buy"+d[i].Symbol+"]")){
                        var selldata=$("input[name=sell"+d[i].Symbol+"]").val();
                        var buydata=$("input[name=buy"+d[i].Symbol+"]").val();
                    }
                    if(selldata){
                          if(selldata == d[i].BP1){
                              str1+='<div class="stock_sell keep_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].BP1;

                          }else if(selldata < d[i].BP1){
                              str1+='<div class="stock_sell up_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].BP1;
                              str1+='<img src="'+J_up+'" class="up_down" alt="" />';

                          }else{
                              str1+='<div class="stock_sell down_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].BP1;
                              str1+='<img src="'+J_down+'" class="up_down" alt="" />';
                          }
                    }else{
                              str1+='<div class="stock_sell up_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].BP1;
                              str1+='<img src="'+J_up+'" class="up_down" alt="" />';
                    }

                    str1+='</p><p>卖出价</p></div>';

                    //如果页面不是第一次加载，也就是说数据已经存在的话，做对比，更改样式和图片    买入
                    if(buydata){
                          if(buydata == d[i].SP1){
                              str1+='<div class="stock_buy keep_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].SP1;

                          }else if(buydata < d[i].SP1){
                              str1+='<div class="stock_buy up_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].SP1;
                              str1+='<img src="'+J_up+'" class="up_down" alt="" />';

                          }else{
                              str1+='<div class="stock_buy down_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].SP1;
                              str1+='<img src="'+J_down+'" class="up_down" alt="" />';
                          }
                    }else{
                              str1+='<div class="stock_buy down_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                              str1+=d[i].SP1;
                              str1+='<img src="'+J_up+'" class="up_down" alt="" />';
                    }



                    str1+='</p><p>买入价</p></div>';
                    str1+='<input type="hidden" name="sell'+d[i].Symbol+'" value='+d[i].BP1+'>';
                    str1+='<input type="hidden" name="buy'+d[i].Symbol+'" value='+d[i].SP1+'></li>';

                }else if(d[i].Symbol == 'FXNYOL20'){
                    str2+='<li class='+d[i].Symbol+'>';
                    str2+='<div class="stock_top">';
                    str2+='<div style="width:40px;height:30px;margin-top: 3px;"><img src="'+pingzhongImg+d[i].Symbol+'.png" alt="" /></div>';
                    str2+='<span class="currency">';
                    str2+=d[i].Symbol.substr(2);
                    str2+='</span><span class="chinaname">'+d[i].Name+'</span></div>';
                    str2+='<p class="stock_time">时间<span>';
                    str2+=d[i].Date;
                    str2+='</span></p>';

                    //如果页面不是第一次加载，也就是说数据已经存在的话，做对比，更改样式和图片    卖出
                    if($("input[name=sell"+d[i].Symbol+"]") && $("input[name=buy"+d[i].Symbol+"]")){
                        var selldata=$("input[name=sell"+d[i].Symbol+"]").val();
                        var buydata=$("input[name=buy"+d[i].Symbol+"]").val();
                    }
                    if(selldata){
                        if(selldata == d[i].BP1){
                            str2+='<div class="stock_sell keep_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                            str2+=d[i].BP1;

                        }else if(selldata < d[i].BP1){
                            str2+='<div class="stock_sell up_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                            str2+=d[i].BP1;
                            str2+='<img src="'+J_up+'" class="up_down" alt="" />';

                        }else{
                            str2+='<div class="stock_sell down_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                            str2+=d[i].BP1;
                            str2+='<img src="'+J_down+'" class="up_down" alt="" />';
                        }
                    }else{
                        str2+='<div class="stock_sell up_active" onclick="showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')"><p class="p'+d[i].Symbol+'">';
                        str2+=d[i].BP1;
                        str2+='<img src="'+J_up+'" class="up_down" alt="" />';
                    }

                    str2+='</p><p>卖出价</p></div>';

                    //如果页面不是第一次加载，也就是说数据已经存在的话，做对比，更改样式和图片    买入
                    if(buydata){
                        if(buydata == d[i].SP1){
                            str2+='<div class="stock_buy keep_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                            str2+=d[i].SP1;

                        }else if(buydata < d[i].SP1){
                            str2+='<div class="stock_buy up_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                            str2+=d[i].SP1;
                            str2+='<img src="'+J_up+'" class="up_down" alt="" />';

                        }else{
                            str2+='<div class="stock_buy down_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                            str2+=d[i].SP1;
                            str2+='<img src="'+J_down+'" class="up_down" alt="" />';
                        }
                    }else{
                        str2+='<div class="stock_buy down_active" onclick="showDiv(this,2,'+d[i].SP1+','+d[i].BP1+')"><p class="p'+d[i].Symbol+'">';
                        str2+=d[i].SP1;
                        str2+='<img src="'+J_up+'" class="up_down" alt="" />';
                    }
                    str2+='</p><p>买入价</p></div>';
                    str2+='<input type="hidden" name="sell'+d[i].Symbol+'" value='+d[i].BP1+'>';
                    str2+='<input type="hidden" name="buy'+d[i].Symbol+'" value='+d[i].SP1+'></li>';
                }
            }
            $("#aaa").html(str1+str2+str);
            $("#bbb").html(str);
            $("#ccc").html(str1);
        //    $("#ddd").html(str2);   //原油
        }
      }
  });

}
// handan 函数封装
function handan(obj){
    if((starttime*1000) > nowtime){
        layer.msg('本周未开盘');
        return false;
    }else if((endtime*1000-60000) < nowtime) { //为了防止时间的误差，所以提前一分钟结束
       
        layer.msg('本周已停盘');
        return false;
    }
    var myDate = new Date;
    var haomao = myDate.getMilliseconds(); //获取当前毫秒数(0-999)
    localStorage.setItem('date',myDate);
    localStorage.setItem('haomao',haomao);

    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    // 获取节点
    if ((userAgent.indexOf("Chrome") > -1)){
        if( $.trim($('#countryname').children().children().html()) == ''){
            var typename = $.trim($("#countryname").html());
            var  direction = $.trim($(".direction").html());
            var  saleNum = $.trim($("#saleNum").html());
            var  buyNum = $.trim($("#buyNum").html());
        }else{
            var typename = $.trim($('#countryname').children().children().html());
            var  direction = $.trim($(".direction").children().children().html());
            var  saleNum = $.trim($("#saleNum").children().children().html());
            var  buyNum = $.trim($("#buyNum").children().children().html());
        }
    }else{
        var typename = $.trim($("#countryname").html());
        var  direction = $.trim($(".direction").html());
        var  saleNum = $.trim($("#saleNum").html());
        var  buyNum = $.trim($("#buyNum").html());
    }

    var  lossWord = $.trim($("#lossWord").val()),
        downWord = $.trim($("#downWord").val());
    var reg=/^[0-9]+$/;
    if(!reg.test(lossWord)) {
        layer.tips('止盈请输入11-499的整数！','#lossWord',{time:1000});
        return false;
    }else if( !isInteger(lossWord)){
        layer.tips('止盈请输入11-499的整数！','#lossWord',{time:1000});
        return false;
    }
    if(!reg.test(downWord)) {
        layer.tips('止损请输入11-99的整数！','#downWord',{time:1000});
        return false;
    }else if( !isInteger(downWord)){
        layer.tips('止损请输入11-99的整数！','#downWord',{time:1000});
        return false;
    }
    // 止盈输入提示
    if(lossWord == ''){
        layer.tips('止盈请输入11-499的整数','#lossWord',{time:1000});
        return;
    }else if(lossWord <= 10){
        layer.tips('止盈请输入11-499的整数','#lossWord',{time:1000});
        return;
    }else if( lossWord >= 500){
        layer.tips('止盈请输入11-499的整数','#lossWord');
        return;
    }
    // 止损输入提示
    if(downWord == ''){
        layer.tips('止损请输入11-99的整数','#downWord',{time:1000});
        return;
    }else if(downWord >100 || downWord <11){
        layer.tips('止损请输入11-99的整数','#downWord',{time:1000});
        return;
    }else if( downWord >= 100){
        layer.tips('止损请输入11-99的整数','#downWord');
        return;
    }

    var label = $("#label").attr('checked');
    if(!label){
        layer.tips('仔细阅读《EAI订阅协议书》，并同意接纳条款','#label',{time:1000});
        return;
    }

    $(obj).removeAttr('onclick');
    $(obj).css('background','#424254');

    if(direction == '空'){
        var  status = 1;
        var cur_point = saleNum;
        var other_point = buyNum;
    }else if(direction == '多'){
        var status = 0;
        var cur_point = saleNum;
        var other_point = buyNum;
    }

    if(typename != '' && direction != '' && saleNum != '' && buyNum != ''){
      $.ajax({
            url:posturl,
            type: 'post',
            data: {typename:typename,status:status,cur_point:cur_point,other_point:other_point,target_loss_point:downWord,target_profit_point:lossWord},
            dataType: "json",
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            success: function(d){
                if(d.status == 1){
                  layer.msg('订阅成功！');
                  $("#lossWord").val('');
                  $("#downWord").val('');
                  hideDiv();
                  window.location.reload();
                }else if(d.status == 2){
                    layer.msg('请先<a href="'+J_login+'">登录</a>！');
                }else{
                    layer.msg('订阅失败，请正确操作！');
                    hideDiv();
                    window.location.reload();
                }
              }
        });
    }
}
//显示提示信息弹框
function showDiv(obj,status,point,bpoint){
    if((starttime*1000) > nowtime){
        layer.msg('本周未开盘');
        return false;
    }else if((endtime*1000) < nowtime) {
        layer.msg('本周已停盘');
        return false;
    }
    $('.showBox1').css('display','none');
    $('.showBox2').css('display','none');
  
    // 判段做空
    var str = '';
    //此处的typename是全局变量，不可以动    
    if(status == 1){
        str = '空';
        typename  = $(obj).prev().prev().find('span').html();
        var fangxiang = 1;
    }else{
        str = '多';
        typename  = $(obj).prev().prev().prev().find('span').html();
        var fangxiang = 0;
    }
    $('.typeCountry img').attr('src',J_tan+typename+'.png');
    
  $.ajax({
        url:J_hold,
        type: 'post',
        data: {typename:typename,'point':point,'fangxiang':fangxiang},
        dataType: "json",
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        success: function(d){
            if(d.status == 3){
                layer.msg('持仓状态不能超过3单！');
            }else if(d.status == 2){
                showCeng();
                $('#tanCeng>a>button').hide();
                $("#tanCeng").css({'width':'250px','height':'80px','line-height':'80px'}).html('请先<a href="'+J_login+'" style="cursor:pointer;color:#3b9ce0;font-size: 20px;">登录</a>！');
            }else if(d.status == 0){
                // layer.msg('同一品种下持仓状态不超过1单！');
                layer.msg(d.msg);
            }else if(d.status == 5){
                layer.msg('请正确操作！');
            }else if(d.status == 4){  //未完善资料信息，请先完善资料
                
                showCeng();
                $('#tanCeng>a>button').hide();
                $("#tanCeng").html("您未完善资料，<a href='"+gowanshan+"' style='cursor:pointer;color:#3b9ce0;'>请完善资料!</a>");
            }else{
                document.getElementById('salePop').style.display="block";
                $(".direction").html(str);
                type = status;
                $('#saleNum').html(point);
                $('#buyNum').html(bpoint);
                $('#countryname').html(typename);
                $("#numUp").html(point);
                $("#numDown").html(point);
            }
          }
    });
}
//修改止盈止损  取消按钮
function goCancel(tradeid,typename,point,target_point,type){  
    if(type == 1){  //止盈
        $("#profit_"+tradeid).find("#profitPoint_"+typename).val(point);
        $("#profit_"+tradeid).find(".user_set_profile_"+typename).html(target_point);
    }else{
        $("#loss_"+tradeid).find("#lossPoint_"+typename).val(point);
        $("#loss_"+tradeid).find(".user_set_loss_"+typename).html(target_point);
    }
}
//用户输入止损点数 onkeyup
function userInputLoss(begin_point,buytype,typename,tradeid,other_begin_point){
    var user_input_point = parseInt($("#loss_"+tradeid).find("#lossPoint_"+typename).val());
    if(!user_input_point){
        user_input_point=0;
    }
    if($.trim(buytype) == '买入'){
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10)).toFixed(2);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(3);
            }else{
                var lastpoint = (parseFloat(other_begin_point) - parseFloat(user_input_point/100)).toFixed(3);
            }
            
        }else{
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10000)).toFixed(5);
            }else{
                var lastpoint = (parseFloat(other_begin_point) - parseFloat(user_input_point/10000)).toFixed(5);
            }
            
        }
    }else{
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10)).toFixed(2);
            //alert(lastpoint);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(3);
            }else{
                var lastpoint = (parseFloat(other_begin_point) + parseFloat(user_input_point/100)).toFixed(3);
            }
        }else{
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10000)).toFixed(5);
            }else{
                var lastpoint = (parseFloat(other_begin_point) + parseFloat(user_input_point/10000)).toFixed(5);
            }
            
        }
    }
    $("#loss_"+tradeid).find(".user_set_loss_"+typename).html(parseFloat(lastpoint));
}
//修改止盈点数onkeyup
function userInputProfit(begin_point,buytype,typename,tradeid,other_begin_point){
    var user_input_point = parseInt($("#profit_"+tradeid).find("#profitPoint_"+typename).val());
    if(!user_input_point){
        user_input_point=0;
    }
    if($.trim(buytype) == '买入'){
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10)).toFixed(2);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(3);
            }else{
                var lastpoint = (parseFloat(other_begin_point) + parseFloat(user_input_point/100)).toFixed(3);
            }
            
        }else{
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10000)).toFixed(5);
            }else{
                var lastpoint = (parseFloat(other_begin_point) + parseFloat(user_input_point/10000)).toFixed(5);
            }
        }
    }else{
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10)).toFixed(2);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(3);
            }else{
                var lastpoint = (parseFloat(other_begin_point) - parseFloat(user_input_point/100)).toFixed(3);
            }
            
        }else{
            if(typename.indexOf('USD')>0){ //如果是交叉盘
                var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10000)).toFixed(5);
            }else{
                var lastpoint = (parseFloat(other_begin_point) - parseFloat(user_input_point/10000)).toFixed(5);
            }
        }
    }
    $("#profit_"+tradeid+" .user_set_profile_"+typename).html(parseFloat(lastpoint));
}
//修改止盈止损 点击向下箭头图片
function updatePoint(typename,type,tradeid){
    $('.showBox1').css('display','none');
    $('.showBox2').css('display','none');
    hideDiv();
    if(type == 1){
        $("#profit_"+tradeid).css('display','block');
    }else{
        $("#loss_"+tradeid).css('display','block');
    }
}
function go_stop(tradeid,name,buy_status){    // 平仓操作
    if((starttime*1000) > nowtime){
        layer.msg('本周未开盘');
        return false;
    }else if((endtime*1000) < nowtime) {
        layer.msg('本周已停盘');
        return false;
    }
    var final_point = $("#"+tradeid).find("span").html();
    
    if(name.indexOf('USD')>0){ //此处判断是否是交叉盘
        if(buy_status == '买入'){
            var end_point = $("ul#aaa").children(".FX"+name).find('input[name=buyFX'+name+']').val();
        }else{
            var end_point = $("ul#aaa").children(".FX"+name).find('input[name=sellFX'+name+']').val();
        }
    }else{  //如果是交叉盘
        if(buy_status == '买入'){
            var end_point = $("ul#aaa").children(".FX"+name).find('input[name=sellFX'+name+']').val();
        }else{
            var end_point = $("ul#aaa").children(".FX"+name).find('input[name=buyFX'+name+']').val();
        }
    }
        
    $.ajax({
        url:gourl,
        type:'post',
        async: false,
        data:{end_point:end_point,tradeid:tradeid,buy_status:buy_status,name:name,final_point:final_point,pingcangType:pingcangType},
        dataType:'json',
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        success:function(res){
            if(res.status == 1){
                    layer.msg('操作成功！');
                    window.location.reload();
            }else{
                layer.msg('操作失败，请重新操作！');
            }
        }
    });
}
//修改止盈止损  确定按钮
function goUpdatePoint(buytype,tradeid,typename,obj,point,targetPoint,buydirect,open_point){
  var updateMyPoint = 0; 
    $(obj).removeAttr("onclick");
    var currpoint = $("#curr_"+tradeid+" input[name=curr_FX"+typename+"]").val();
    if(buytype == 2){  //止盈
        var profitpoint = parseInt($.trim($("#profit_"+tradeid).find("#profitPoint_"+typename).val()));  //用户输入的止盈点数 input框
        if(!profitpoint) profitpoint = 0;
        if(profitpoint <= 10 || profitpoint >= 500){  //用户输入的止盈点数小于等于10
            layer.tips('止盈请输入11-499的整数！','#profitPoint_'+typename,{time:3000});
            $(obj).attr("onclick","goUpdatePoint('"+buytype+"','"+tradeid+"','"+typename+"',this,'"+point+"','"+targetPoint+"','"+buydirect+"','"+open_point+"')");
            updateMyPoint = 0;
            return false;
        }else{
            $("#profit_"+typename).find(".sureBtn").val('修改中...');
            var lastProfitPoint=$.trim($("#profit_"+tradeid).find(".user_set_profile_"+typename).html());
            var losspoint = 0;
            var lastLossPoint= 0;
            updateMyPoint = 1;
        }
    }else{ //止损
        var losspoint = parseInt($.trim($("#loss_"+tradeid).find("#lossPoint_"+typename).val()));
        var set_curr_point = $.trim($("#loss_"+tradeid).find(".user_set_loss_"+typename).html()); //用户修改以后的止损点位
        var setpoint  = point_diff(typename,currpoint,open_point); //计算以后可设置的最小点差
        if(!losspoint) losspoint = 0;
        if(losspoint <= 10 || losspoint >= 100){  //用户输入的止损点数小于等于10 或者大于等于100
            layer.tips('止损点数必须大于10，小于100<br/>最小可设置为'+setpoint,$("#lossPoint_"+typename),{time:3000});
            $(obj).attr("onclick","goUpdatePoint('"+buytype+"','"+tradeid+"','"+typename+"',this,'"+point+"','"+targetPoint+"','"+buydirect+"','"+open_point+"')");
            updateMyPoint = 0;
            return false;
        }else if((set_curr_point > currpoint) && (buydirect == '买入')){ //不能修改
            layer.tips('止损点数必须大于10，小于100<br/>最小可设置为'+setpoint,$("#lossPoint_"+typename),{time:3000});
            $(obj).attr("onclick","goUpdatePoint('"+buytype+"','"+tradeid+"','"+typename+"',this,'"+point+"','"+targetPoint+"','"+buydirect+"','"+open_point+"')");
            updateMyPoint = 0;
            return false;
        }else if((set_curr_point < currpoint) && (buydirect == '卖出')){ //不能修改
            layer.tips('止损点数必须大于10，小于100<br/>最小可设置为'+setpoint,$("#lossPoint_"+typename),{time:3000});
            $(obj).attr("onclick","goUpdatePoint('"+buytype+"','"+tradeid+"','"+typename+"',this,'"+point+"','"+targetPoint+"','"+buydirect+"','"+open_point+"')");
            updateMyPoint = 0;
            return false;
        }else{
            $("#loss_"+typename).find(".sureBtn").val('修改中...');
            var lastLossPoint=$.trim($("#loss_"+tradeid).find(".user_set_loss_"+typename).html());
            var profitpoint = 0;
            var lastProfitPoint = 0;
            updateMyPoint = 1;
        }
    }
    
    if(updateMyPoint ==1){
        $.ajax({
            url:updateurl,
            type: 'post',
            data: {'tradeid':tradeid,'profitPoint':profitpoint,'lossPoint':losspoint,'lastProfitPoint':lastProfitPoint,'lastLossPoint':lastLossPoint},
            dataType: "json",
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            success: function(d){
                if(d == 1){
                    if(buytype == 2){
                        $("#profit_"+tradeid).css('display','none');
                        $("#profit_"+tradeid).parent().find('span:eq(0)').html(lastProfitPoint);
                        $("#profit_"+tradeid).find("#profitPoint_"+typename).val(profitpoint);
                        $(obj).attr("onclick","goUpdatePoint('"+buytype+"','"+tradeid+"','"+typename+"',this,'"+profitpoint+"','"+lastProfitPoint+"','"+buydirect+"','"+open_point+"')");
                        $(obj).prev().removeAttr("onclick");
                        $(obj).prev().attr("onclick","goCancel('"+typename+"','"+profitpoint+"','"+lastProfitPoint+"',1)");
                    }else{
                        $("#loss_"+tradeid).css('display','none');
                        $("#loss_"+tradeid).parent().find('span:eq(0)').html(lastLossPoint);
                        $("#loss_"+tradeid).find("#lossPoint_"+typename).val(losspoint);
                        $(obj).attr("onclick","goUpdatePoint('"+buytype+"','"+tradeid+"','"+typename+"',this,'"+losspoint+"','"+lastLossPoint+"','"+buydirect+"','"+open_point+"')");
                        $(obj).prev().removeAttr("onclick");
                        $(obj).prev().attr("onclick","goCancel('"+typename+"','"+losspoint+"','"+lastLossPoint+"',0)");
                    }
                    layer.msg('修改成功');
                }else{
                    layer.msg('修改失败');
                    $(obj).attr("onclick","goUpdatePoint('"+buytype+"','"+tradeid+"','"+typename+"',this,'"+point+"','"+targetPoint+"','"+buydirect+"','"+open_point+"')");
                }
                $("#profit_"+tradeid).find(".sureBtn").val('确定');
                $("#loss_"+tradeid).find(".sureBtn").val('确定');
            }
        });
    }
}
//我的订阅 -> 当前价格
function current_price(buy_status,typename,tradeid){
    var price='';
    if(buy_status == '买入'){
        var newprice = price = $("ul#aaa").children(".FX"+typename).find('input[name=buyFX'+typename+']').val();
    }else{
        var newprice =  price = $("ul#aaa").children(".FX"+typename).find('input[name=sellFX'+typename+']').val();
    }
    var oldprice=$("#curr_"+tradeid+" input[name=curr_FX"+typename+"]").val();  //上一个0.3s的值
    if(oldprice == ''){  //如果页面第一次加载
        price += '<img  src="'+golow+'" alt="">';
        $(".orderTab #curr_"+tradeid+" .FX"+typename).html(price);
    }else{
        var res_price = parseFloat(price) - parseFloat(oldprice);

        if(res_price > 0){   //如果当前的数据大于上一个0.3s的值
            price += '<img  src="'+goup+'" alt="">';
            $(".orderTab #curr_"+tradeid+" .FX"+typename).html(price);
        }else if(res_price < 0){ //如果当前的数据小于上一个0.3s的值
            price += '<img  src="'+golow+'" alt="">';
            $(".orderTab #curr_"+tradeid+" .FX"+typename).html(price);
        }
    }
    $("#curr_"+tradeid+" input[name=curr_FX"+typename+"]").val(newprice);
}
//我的订阅 -》 盈亏点位
function profile_loss(buy_status,typename,begin_point,tradeid) {
    if(typename.indexOf('USD')>0){ //此处是判断是否是交叉盘
        if (buy_status == '买入') {    // 拿到当前实时变化的价格
            var price = $("ul#aaa").children(".FX"+typename).find('input[name=buyFX'+typename+']').val();
        } else {
            var price = $("ul#aaa").children(".FX"+typename).find('input[name=sellFX'+typename+']').val();
        }
    }else{
        if (buy_status == '买入') {    // 拿到当前实时变化的价格
            var price = $("ul#aaa").children(".FX"+typename).find('input[name=sellFX'+typename+']').val();
        } else {
            var price = $("ul#aaa").children(".FX"+typename).find('input[name=buyFX'+typename+']').val();
        }
    }
    
    if(buy_status == '卖出'){
        if (typename == 'XAUUSD') {
            var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(1))*10).toFixed(2);
        } else if (typename == 'NYOL20'){
            var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(0.1))*100).toFixed(2);
        }else if( typename.indexOf('JPY')>0){
            var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(0.1))*100).toFixed(3);
        }else{
            var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(0.001))*10000).toFixed(5);
        }
    }else{
        if (typename == 'XAUUSD') {
            var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(1))* 10).toFixed(2) ;
        } else if (typename == 'NYOL20'){
              var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(0.1))* 100).toFixed(2);
        }else if( typename.indexOf('JPY')>0){
              var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(0.1))* 100).toFixed(3);
        }else{
              var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(0.001))* 10000).toFixed(5);
        }
    }

    var oldprice = $("#"+tradeid+" input[name=oldpot_FX"+typename+"]").val();
    if(oldprice != ''){
        var newpotprice = parseFloat(lastprice) - parseFloat(oldprice);
        if(newpotprice > 0){
            $("#"+tradeid).find('span').css({'color':'#f7512b'});
        }else if(newpotprice < 0){
            $("#"+tradeid).find('span').css({'color':'#27a885'});
        }else{

        }
    }else{
          $("#"+tradeid).find('span').css({'color':'#8c8c8c'});
    }

    $(".orderTab #"+tradeid+" span").html(parseFloat(lastprice));
    $("#"+tradeid+" input[name=oldpot_FX"+typename+"]").val(parseFloat(lastprice));
}

// 点击保损按钮操作判断
function insureLossButton(tradeid){    
    if((starttime*1000) > nowtime){
        layer.msg('本周未开盘');
        return false;
    }else if((endtime*1000) < nowtime) {
        layer.msg('本周已停盘');
        return false;
    }
    
    
    var final_point = $("#"+tradeid).find("span").html();
    if(final_point <= 0){
        layer.msg('当前盈利点位为负,无法操作！');
    }else{
        //弹窗
    }
}

//确认修改保损值
function  confirmInsureLoss(tradeid,typename,buy_status){
    var final_point = $("#"+tradeid).find("span").html(); //当前的盈利点位
    var insureLossPoint = 0; //拿到用户输入的保损值 
    
    if(final_point <= 0){
        layer.msg('当前盈利点位为负,无法操作！');
    }else if(insureLossPoint > final_point || insureLossPoint < 0){
        layer.msg('保损点位必须大于0，小于当前盈利点位！');
    }else{
        $.ajax({
            url  : updateinsureloss,
            type : 'post',
            data : {'insureLossPoint':insureLossPoint,'tradeid':tradeid,'finalPoint':final_point},
            dataType: "json",
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            success:function(res){
                if(res == 1){
                     layer.msg('操作成功！');
                }else{
                     layer.msg('操作失败！');
                }
            }
        })
    }
}
